package com.ysg.widget.dialog;

import android.content.Context;
import android.view.Window;
import android.widget.TextView;
import com.ysg.R;
import com.ysg.base.BaseDialog;
import com.ysg.utils.YImageUtil;
import com.ysg.utils.YStringUtil;
import com.ysg.widget.image.HeartImageView;

/**
 * 守护对话框
 */
public class GuardDialog extends BaseDialog {
    public interface OnConfirmListener{
        void onConfirmClick();
    }
    private OnConfirmListener listener;
    public void setOnConfirmListener(OnConfirmListener listener){
        this.listener = listener;
    }

    private String pic, nickName, count;
    private TextView tvName, tvNumber, tvCancel, tvConfirm;
    private HeartImageView avatar;
    public GuardDialog(Context context, String pic, String nickName, String count) {
        super(context);
        this.pic = pic;
        this.nickName = nickName;
        this.count = count;
    }


    @Override
    public int getLayoutId() {
        return R.layout.dialog_guard;
    }

    public void initView() {
        avatar = findViewById(R.id.avatar);
        tvName = findViewById(R.id.tvName);
        tvNumber = findViewById(R.id.tvNumber);
        tvName = findViewById(R.id.tvName);
        tvCancel = findViewById(R.id.tvCancel);
        tvConfirm = findViewById(R.id.tvConfirm);
    }

    @Override
    protected void initAnimation() {
        super.initAnimation();
        Window window = getWindow();
//        window.setWindowAnimations(R.style.dialog_animation);
    }

    @Override
    public void initData() {
        if (YStringUtil.isNotEmpty(pic)){
            YImageUtil.show(avatar, pic);
        }
        if (YStringUtil.isNotEmpty(nickName)){
            tvName.setText(nickName);
        }
        if (YStringUtil.isNotEmpty(count)){
            String tip = String.format(getContext().getResources().getString(R.string.dialog_guard_tip), count);
            tvNumber.setText(tip);
        }
    }

    @Override
    public void initListener() {
        tvCancel.setOnClickListener((v)->{
            dismiss();
        });
        tvConfirm.setOnClickListener((v)->{
            dismiss();
            if (listener != null){
                listener.onConfirmClick();
            }
        });
    }


}
